package com.whalehearing.tingyou.web.controller.hearing;

import java.util.List;
import java.util.Arrays;
import javax.servlet.http.HttpServletResponse;

import com.whalehearing.tingyou.common.annotation.DataSource;
import com.whalehearing.tingyou.common.enums.DataSourceType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.whalehearing.tingyou.common.annotation.Log;
import com.whalehearing.tingyou.common.core.controller.BaseController;
import com.whalehearing.tingyou.common.core.domain.AjaxResult;
import com.whalehearing.tingyou.common.enums.BusinessType;
import com.whalehearing.tingyou.domain.HearingDetailedQuestionnaire;
import com.whalehearing.tingyou.service.IHearingDetailedQuestionnaireService;
import com.whalehearing.tingyou.common.utils.poi.ExcelUtil;
import com.whalehearing.tingyou.common.core.page.TableDataInfo;

/**
 * 详细问卷Controller
 *
 * @author zengjun-qxm
 * @date 2024-09-20
 */
@Api(tags="详细问卷管理")
@RestController
@RequestMapping("system/hearing/questionnaire")
public class HearingDetailedQuestionnaireController extends BaseController
{
    @Autowired
    private IHearingDetailedQuestionnaireService hearingDetailedQuestionnaireService;

    /**
     * 查询详细问卷列表
     */
    @ApiOperation("查询详细问卷列表")
    @PreAuthorize("@ss.hasPermi('hearing:questionnaire:list')")
    @GetMapping("/list")
    public TableDataInfo list(HearingDetailedQuestionnaire hearingDetailedQuestionnaire)
    {
        startPage();
        List<HearingDetailedQuestionnaire> list = hearingDetailedQuestionnaireService.selectHearingDetailedQuestionnaireList(hearingDetailedQuestionnaire);
        return getDataTable(list);
    }

    /**
     * 导出详细问卷列表
     */
    @ApiOperation("导出详细问卷列表")
    @PreAuthorize("@ss.hasPermi('hearing:questionnaire:export')")
    @Log(title = "详细问卷", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HearingDetailedQuestionnaire hearingDetailedQuestionnaire)
    {
        List<HearingDetailedQuestionnaire> list = hearingDetailedQuestionnaireService.selectHearingDetailedQuestionnaireList(hearingDetailedQuestionnaire);
        ExcelUtil<HearingDetailedQuestionnaire> util = new ExcelUtil<HearingDetailedQuestionnaire>(HearingDetailedQuestionnaire.class);
        util.exportExcel(response, list, "详细问卷数据");
    }

    /**
     * 获取详细问卷详细信息
     */
    @ApiOperation("获取详细问卷详细信息")
    @PreAuthorize("@ss.hasPermi('hearing:questionnaire:query')")
    @GetMapping(value = "/{detailedQuestionnaireId}")
    public AjaxResult getInfo(@PathVariable("detailedQuestionnaireId") Long detailedQuestionnaireId)
    {
        return success(hearingDetailedQuestionnaireService.getById(detailedQuestionnaireId));
    }

    /**
     * 新增详细问卷
     */
    @ApiOperation("新增详细问卷")
    @PreAuthorize("@ss.hasPermi('hearing:questionnaire:add')")
    @Log(title = "详细问卷", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HearingDetailedQuestionnaire hearingDetailedQuestionnaire)
    {
        return toAjax(hearingDetailedQuestionnaireService.save(hearingDetailedQuestionnaire));
    }

    /**
     * 修改详细问卷
     */
    @ApiOperation("修改详细问卷")
    @PreAuthorize("@ss.hasPermi('hearing:questionnaire:edit')")
    @Log(title = "详细问卷", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HearingDetailedQuestionnaire hearingDetailedQuestionnaire)
    {
        return toAjax(hearingDetailedQuestionnaireService.updateById(hearingDetailedQuestionnaire));
    }

    /**
     * 删除详细问卷
     */
    @ApiOperation("删除详细问卷")
    @PreAuthorize("@ss.hasPermi('hearing:questionnaire:remove')")
    @Log(title = "详细问卷", businessType = BusinessType.DELETE)
	@DeleteMapping("/{detailedQuestionnaireIds}")
    public AjaxResult remove(@PathVariable Long[] detailedQuestionnaireIds)
    {
        return toAjax(hearingDetailedQuestionnaireService.removeByIds(Arrays.asList(detailedQuestionnaireIds)));
    }
}
